
<template>
	<div class="index">

		<div class="center">
			<left></left>
			<div class="right">
          <top></top>
          <div class="hei10"></div>

		<div class="where" style="background: #fff; padding: 10px 30px; font-size: 14px; color: #595959;">
		  当前位置：
		  <router-link to="/index" style="color: #409eff;">分销后台</router-link>>
		  <router-link to="/finance/zhichu" style="color: #409eff;">核算支出</router-link>>
		  佣金校验
		</div>

          <div class="hei10"></div>
                <div class="conlist" v-loading='loading'>
                  <el-form ref="form" @submit.native.prevent :model="form" label-width="120px" class="form">
                        <el-form-item label="分销商:">
                            <el-input v-model="merchant_name" placeholder="请输入分销商名称"></el-input>
                        </el-form-item>
                        <el-form-item label="商品编码:">
                            <el-input v-model="sku" placeholder="请输入商品编码"></el-input>
                        </el-form-item>
                        <el-form-item label="订单ID:" style="position: relative;">
                            <el-input v-model="order_id" placeholder="请输入订单ID"></el-input>
                            <span
                            	style="position: absolute; right: -18px; top: 0px; color: #1989FA; font-size: 16px; cursor: pointer; z-index: 99;"
                            	@click="duoxuanlog3 = true">
                            	<i class="el-icon-circle-plus"></i>
                            </span>
                        </el-form-item>
                        <el-form-item label="状态更新时间:">
                            <el-date-picker style="width: 470px;"  v-model="update_time"  @change="fixtime" value-format="yyyy-MM-dd HH:mm:ss"  type="datetimerange" range-separator="——" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                        </el-form-item>

                  </el-form>
                  <el-button type="danger" style="margin-left: 110px;" @click="search">搜索</el-button>
                 <el-button style="margin-left: 30px;" @click="zhichufix" v-if="shop_id2 == 311784 || shop_id2 == 521161 || shop_id2 == 397353 || shop_id == 303593">批量修改支出佣金</el-button>

                    <div class="list" style="margin-top: 30px;">
                        <div class="th"><input type="checkbox" @change="quanxuan" value="0" v-model="quanxuana" />全选</div>
                        <div class="th">订单ID</div>
                        <div class="th">分销商名称</div>
                        <div class="th">商品名称</div>
                        <div class="th">商品编码</div>
                        <!-- <div class="th">佣金发放类型</div> -->
                        <div class="th">佣金收入</div>
                        <div class="th">佣金支出</div>
                        <div class="th">状态更新时间</div>
                        <div class="th">订单创建时间</div>
                    </div>
                    <div class="list" v-for="item in list" :key="item.id">
                        <div class="td"><input type="checkbox" :value="item.id" @change="danxuan" v-model="danxuans" /></div>
                        <div class="td">{{item.order_id}}</div>
                        <div class="td">{{item.name}}</div>
                        <div class="td">{{item.product_sku}}</div>
                        <div class="td">{{item.source_sku}}</div>
                        <div class="td">{{item.amount | qux}}</div>
                        <div class="td">{{item.commission_amount | qux}}</div>
                        <div class="td">{{item.updated_at}}</div>
                        <div class="td">{{item.created_at}}</div>
                    </div>
                    <el-pagination background layout="total,prev, pager, next" :current-page="page" @current-change="fanye" :page-size="pagesize" :total="total"></el-pagination>
                </div>
            </div>
        </div>
        <el-dialog :title="choose.mobile" :visible.sync="tongjilog" width="400px" :close-on-click-modal='false'>
            <div class="daowei">所属商品编码:<span class="daowei2">{{choose.good_sku}}</span></div>
            <div class="daowei">返利次数:<span class="daowei2">{{choose.cycle}}</span></div>
            <div class="daowei">已领取次数:<span class="daowei2">{{choose.rebate_cycle}}</span></div>
            <div class="daowei">已领取积分:<span class="daowei2">{{choose.points}}</span></div>
            <div class="daowei">已充值话费:<span class="daowei2">{{choose.recharged_amount}}</span></div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="tongjilog = false">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog title="多个外部订单编号搜索" :visible.sync="duoxuanlog3" :close-on-click-modal="false" width="600px">
        	<div>
        		<el-input type="textarea" :rows="10" placeholder="一行一个，可直接粘贴excel纵列数据" v-model="duoxuanids3"></el-input>
        	</div>
        	<div slot="footer" class="dialog-footer">
        		<el-button type="primary" size="small" @click="search3">搜索</el-button>
        	</div>
        </el-dialog>

        <el-dialog title="导入结果" :visible.sync="shoplog" :close-on-click-modal="false" width="600px">
              <div>
                  <div style="color: #077ECE; line-height: 30px;">成功{{shoplist.success}}条</div>
                  <div style="color: #DF3434; line-height: 30px;">失败及原因：
                      <div v-for="(item,i) in shoplist.erros" :key="i">
                          {{item}}
                      </div>
                  </div>
              </div>
              <div slot="footer" class="dialog-footer">
                  <el-button type="primary" size="small"  @click="shoplog = false">好的</el-button>
              </div>
        </el-dialog>


        <!-- <el-dialog title="批量修改支出佣金" :visible.sync="zhichulog" :close-on-click-modal="false" width="600px">
              <div>
                  <el-input v-model="zhichuyongjin" placeholder="请输入要修改的支出佣金金额"></el-input>
              </div>
              <div slot="footer" class="dialog-footer">
                  <el-button type="primary" size="small"  @click="zhichulog = false">确认</el-button>
              </div>
        </el-dialog> -->

        <!-- <foot></foot> -->
    </div>

</template>

<script>
    import qu0 from '../../../public/qu0.js'
    import axios from 'axios'
    import top from '@/components/top.vue'
    import left from '@/components/left.vue'
    import foot from '@/components/foot.vue'
    import moment from "moment";
    import UploadExcelComponent from "@/components/UploadExcel/index.vue";
    export default {
        components: {
            "left": left,
            "top": top,
            "foot": foot,
            UploadExcelComponent

        },
        name: "zhichunew",
        data() {
            return {
                name:"",
                qrstatus:"2",
                qrmonth:"",
                form:{},
                monthfixlog:false,
                monthfix:"",
                monthfixall:{},
                wenjian:"",
                shoplog:false,
                shoplist:"",

                btnname:"点击导入",
                uploading:true,
                fanliuploadlog:false,
                uploadsuceess:"",
                uploadtimes:"",
                uploadmon1:"",
                uploadmon2:"",
                uploadmon3:"",
                uptime:"",
                month:"",
                monthsearch:"",
                total:0,
                pagesize:100,
                page:1,
                list:"",
                loading:true,
                mobile:"",
                sku:"",
                order_id:"",
                update_time:"",
                update_start:"",
                update_end:"",
                merchant_name:"",
                merchant_name2:"",
                tongjilog:false,
                choose:{ },
                url:"",
                id:"",
                func_J02:false,
                leader:0,
                daorulog:false,
                shouruname:"",
                zhichulog:false,
                danxuans: [],
                quanxuana: false,
                quanxuans: [],
                duoxuanlog3:false,
                duoxuanids3:"",
                duoxuanids4:"",
                shop_id:"",
		    shop_id2:""
            }
        },
        filters: {
            qux:function(dataStr){
                return qu0.qu0(dataStr)
            }
        },
        created() {
            this.url = window.location.origin+"/"

            //权限问题
            var user = JSON.parse(localStorage.getItem('USER'));
            this.user_func = user.functions
            for( var i in this.user_func){
                var func_number = this.user_func[i].code
                if(func_number.indexOf("J02") >= 0){ this.func_J02 = true }
                if(func_number.indexOf("J01") >= 0){ this.func_J01 = true }
                if(func_number.indexOf("J03") >= 0){ this.leader = 1 }
            }

            var shop = JSON.parse(localStorage.getItem('SHOP'));
            this.shopname = shop.shop_name

            if(this.$route.query.name){
                this.merchant_name = this.$route.query.name
                this.merchant_name2 = this.$route.query.id
            }

            this.getlist()

		//获取店铺id
		axios.get("/api/gth/user/shop").then(response => {
		  if (response.data.msg.code == 0) {
		    this.shop_id2 = response.data.data.shop_id;
		  } else {
		    this.$message.error(response.data.msg.info);
		  }
		});

            //获取店铺id
            // axios.get("/api/gth/user/shop").then(response => {
            //   if (response.data.msg.code == 0) {
            //     this.shop_id = response.data.data.shop_id;
            //   } else {
            //     this.$message.error(response.data.msg.info);
            //   }
            // });
            this.shop_id = JSON.parse(localStorage.getItem('USER')).id;

        },
        mounted() {

        },
        methods: {
          search3: function() {
          	this.duoxuanids4 = this.duoxuanids3.split(/\n/)
          	for (let i in this.duoxuanids4) {
          		this.duoxuanids4[i] = this.duoxuanids4[i].trim()
          	}
          	this.page = 1;
          	this.loading = true;
          	this.getlist();
          	this.duoxuanlog3 = false
          },
          //全选的ids集合
          ids: function() {
            var checkids = [];
            for (var i in this.list) {
              checkids.push(this.list[i].id);
            }
            this.quanxuans = checkids;
          },
          //点击全选
          quanxuan: function() {
            if (
              this.danxuans.length != this.quanxuans.length ||
              this.danxuans.length == 0
            ) {
              this.danxuans = this.quanxuans;
              this.quanxuana = true;
            } else {
              this.danxuans = [];
              this.quanxuana = false;
            }
          },
          //点击单选
          danxuan: function() {
            // this.choosearea.push(this.checkedarea)
            if (this.danxuans.length == this.quanxuans.length) {
              this.quanxuana = true;
            } else {
              this.quanxuana = false;
            }
          },
            zhichufix:function(){
                var that = this
                this.$prompt('请输入要修改的支出佣金金额', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                }).then(({ value }) => {

                    axios.post('/api/plan-market/commission/logs/update',{ids:this.danxuans,amount:value})
                        .then(response => {
                            if(response.data.msg.code == 0){
                                that.$message.success('修改成功');
                                that.getlist()
                            }else{
                                that.$message.error(response.data.msg.info);
                            }
                        })
                })

            },
            querenzhichu:function(id){
              this.loading = true
              var that = this;
              axios.post('/api/plan-market/expend/confirm',{id:id})
              	.then(response => {
              		if(response.data.msg.code == 0){
                    that.getlist()
              		}else{
              			if(response.data.msg.code == 50401){that.$router.push({ path: "/login" }); return false}
              			that.$message.error(response.data.msg.info);
              		}
              	})
            },
            down:function(url){
              const a = document.createElement('a');
              a.setAttribute('href', this.url + url);
              a.click();
            },
            //生成支出
            shengchengzhichu:function(){

                var that = this
                axios.post('/api/plan-market/expend/all/export')
                    .then(response => {
                        if(response.data.msg.code == 0){
                            that.loading = true
                            that.getlist()
                        }else{
                            that.$message.error(response.data.msg.info);
                        }
                    })
            },

            //修改时间
          fixtime:function(){
              if(this.update_time != null){
                this.update_start = this.update_time[0]
                this.update_end = this.update_time[1]
              }else{
                this.update_start = ''
                this.update_end = ''
              }

          },


            search:function(){
                this.loading = true
                this.page = 1
                this.getlist()
            },
            //翻页
            fanye:function(page){
            	this.loading = true
            	this.page = page
            	this.getlist()
            },
            //获取列表
            getlist:function(){
                var that = this
                if(this.monthsearch == null){
                    this.monthsearch = ''
                }
                axios.get('/api/plan-market/merchant/commission/logs?file_status=-1&page='+this.page+'&page_size='+this.pagesize+'&update_start='+this.update_start+'&update_end='+this.update_end+
                '&merchant_name='+this.merchant_name+'&file_id='+this.merchant_name2+'&sku='+this.sku+'&order_id='+this.order_id+'&order_ids='+this.duoxuanids4)
                	.then(response => {
                		if(response.data.msg.code == 0){
                      that.list = response.data.data.data
                      that.total = response.data.data.total
                      that.loading = false
                      that.ids()
                      that.danxuans = []
                		}else{
                			that.$message.error(response.data.msg.info);
                		}
                	})
            },

        }
    }
</script>

<style lang="scss" scoped>
    .index{
        .listupload{ font-size: 14px;
            .li{flex: 1; line-height: 38px; margin-top: 20px;}

        }
        .moneyf{
          .el-button--primary{ background: #409EFF; color: #ffffff; border: none; }
          .el-button{ height: 36px !important;}
          .el-date-editor.el-input, .el-date-editor.el-input__inner{ width: auto;}
        }
        .form{ display: flex; flex-wrap: wrap;
          input{ width: 200px !important;}
        }
        .listth{ font-size: 14px;  border-bottom: 1px #EAEAEA solid; font-weight: bold;}
        .daowei{ margin-bottom: 20px;}
        .daowei2{ color: #DD2727; margin-left: 10px;}
        .moneylist{ display: flex;}
        .erimg{ width: 200px;}
        .red{ border: 1px #FF3B3B solid !important; color: #FF3B3B !important;}
        .moneylist div{ border: 1px #AAAAAA solid; width: 85px; height: 35px; line-height: 35px; text-align: center; margin-right: 10px; cursor: pointer;}

                .title{border-bottom: 1px #EAEAEA solid;  line-height: 45px; padding-left: 30px; font-size: 16px; background: #F9F9F9; color: #727272}

            .el-button{ height: 36px !important;     padding: 9px 30px !important;
            line-height: 14px !important;}
            .powertop{ display: flex; background:#f9f9f9; }
            .powertopli{ flex-basis: 160px; line-height: 45px; border-top: 4px #EBECEF solid; color: #727272; border-right: 1px #EAEAEA solid; font-size: 14px; text-align: center;}
            .powertopact{ background: #FFFFFF; border-top: 4px #DD2727 solid;}
            .con{  background: #FFFFFF; padding: 30px 40px; display: flex; justify-content: space-between;
                .conleft{
                    .flex{ display: flex; margin-bottom: 20px;}
                    .gong{ margin-right: 30px; color: #333;}
                }
                .conright{
                    .el-input__inner{ line-height: 40px !important; height: 40px !important;}
                }
            }
            .conlist{ padding-bottom: 20px; padding-top: 30px; background: #FFFFFF; min-height: 800px;
                .flex{ display: flex; justify-content: space-between}
                .gong{ display: flex; padding: 0 20px;
                .el-button{ height: 36px !important;     padding: 9px 30px !important;
    line-height: 14px !important;}

                    .el-input__inner{ width: 250px;}
                    .el-button--danger{ margin-left: 20px;}
                    .el-button--primary{  background: #EEF7FF; margin-left: 20px; border: 1px #EEF7FF solid; }
                    .el-date-editor--month{ margin-right: 20px;}
                    button{  padding: 10px 20px;}
                }
                .el-form-item{ margin-bottom: 20px;}
                .gl{ margin-bottom: 20px;
                    .el-input__inner{ width: 200px !important; }
                    .el-button--danger{ margin-left: 0px !important; margin-right: 20px;}
                    .el-input__icon{ line-height: 36px;}
                }
                .list{ display: flex; border-bottom: 1px #eaeaea solid;
                    .th{ background: #EAEAEA; text-align: center; flex: 1; padding: 15px 0; font-size: 14px; }
                    .td{ background: #ffffff; text-align: center; flex: 1; padding: 5px 5px; height: 40px; font-size: 14px; line-height: 40px; overflow:
                    hidden;white-space: nowrap;text-overflow: ellipsis;}
                    .td2{ flex: 1; display: flex; justify-content: center; flex-wrap: wrap;}
                }
                .el-pagination{ text-align: right; margin: 20px 0}
            }

    }
</style>
